package cn.t222.controller.sys;

import cn.t222.pojo.Result;
import cn.t222.pojo.SysResources;
import cn.t222.service.ResourceService;
import cn.t222.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.security.Principal;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@Slf4j
public class IndexController {
    @Resource
    private UserService userService;
    @Resource
    private ResourceService resourceService;

    @GetMapping("/index/getResources")
    public Result getResources(Principal principal) {
        String username = principal.getName();
        List<SysResources> list = resourceService.getAllByUsername(username);
        Collections.sort(list, (o1, o2) -> {
            return o1.getId().compareTo(o2.getId());
        });
        return Result.ok("200", "success", list);
    }
}
